package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.domain.Employee;

import cn.wolfcode.domain.Salary;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.SalaryQueryObject;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.service.ISalaryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/sal")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("sqo") SalaryQueryObject sqo,Long id){
        //高级查询
        PageInfo<Salary> pageInfo = salaryService.selectForList(sqo);
        model.addAttribute("pageInfo",pageInfo);
        //查询所有员工
        List<Employee> employees = employeeService.list();
        model.addAttribute("employees",employees);
        //查询单个员工
        //Salary salary = salaryService.selectOne(id);
        //model.addAttribute("salary",salary);

        return "/salary/salary";
    }
    /*@RequestMapping("/input")
    public String input(Model model,Long id){
        Salary salary = salaryService.selectOne(id);
        model.addAttribute("salary",salary);
        //查询所有员工
        List<Employee> employees = employeeService.list();
        model.addAttribute("employees",employees);
       return
    }*/

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Model model, Salary salary){
        if (salary.getId()!=null){
            salaryService.updateByPrimaryKey(salary);
        }else {
            salaryService.insert(salary);
        }
        return "redirect:/sal/list";
    }
}
